home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-19 | 9.7 KB | 493 lines | [TEXT/MWPS] |
- unit LogicSimIntf;
-
- { ** Interface for code ressource LogicSim modules v2.7a ** }
-
- interface
-
- {$SETC INT_TIME := FALSE}
-
- uses
- StdIntfs;
-
- const
- kStimCmdMaxLen = 8;
-
- type
- PinNumT = Integer;
- GateNumT = Integer;
- NodeNumT = Integer; {not used in component def proc}
-
- type
- PinKindT = Integer;
- ExtPinFlagT = Integer;
- DelayModeT = Integer;
-
- type
- PixelT = Integer;
- TickT = Longint;
- PicDirectionT = Integer;
-
- type
- LSProcPtr = ProcPtr;
- LSMessageT = Longint;
- LSVarCodeT = Longint;
-
- type
- ClassNameT = Str63; {too long! should have been Str32}
- ClassIDT = record
- name: ClassNameT;
- end;
- PinNameT = Str63;
- ComponentNameT = Str63;
- LongClassNameT = Str255;
- FamilyNameT = Str32; {= family file name}
- StimCmdT = string[kStimCmdMaxLen];
-
- type
- SValue = Integer;
- {$IFC INT_TIME}
- STime = Longint;
- {$ELSEC}
- STime = Extended;
- {$ENDC}
-
- const {ExtPinFlagT}
- kExtInput = 1;
- kExtOutput = 2;
- kExtInOut = 3;
-
- const {PinKindT}
- kInputPin = 1;
- kOutputPin = 2;
- kInOutPin = 3;
-
- const {PinNumT}
- kAllPins = -1; {for simulation message}
-
- const {STime}
- {$IFC INT_TIME}
- INF_TIME = $7FFFFFFF;
- {$ELSEC}
- INF_TIME = 1.0e20; { INF doesn't work with CW if used as const, why ?}
- {$ENDC}
-
- const {SValue}
- L0 = 0;
- L1 = 1;
- LX = -1; {unknown}
- LZ = -2; {hight impedance}
-
- const {DelayModeT}
- simulMin = 1;
- simulMax = 2;
- simulMean = 3;
- simulRandom = 4;
-
- {Class messages}
-
- const {LSMessageT}
- msgNewClass = 1;
- msgDisposeClass = 2;
-
- type
- PrmClassRec = record
- image: PicHandle;
- name: LongClassNameT;
- id: ClassIDT;
- fileSpec: FSSpec; {reserved}
- becomeExtPin: ExtPinFlagT;
- titleOffset: PixelT; {LS v2.6a2}
- resultCode: OSErr; {LS v2.6a2}
- end;
- PrmClassPtr = ^PrmClassRec;
-
-
- {Symbol messages}
-
- const
- msgNewSymbol = 10;
- msgDisposeSymbol = 11;
- msgSimClick = 12;
- msgDrawSymbol = 13;
- msgOptionDialog = 14;
- msgSymGetCharacs = 15;{ (it was msgCanOptionDialog in older version), used to get the fields "can(something)" }
- msgSetSymbolParams = 16;
- msgGetSymbolParams = 17;
-
- type
- PrmSymbolRec = record
- frame: Rect;
- modifiers: Integer;
- canOptionDialog: Boolean;
- paramsStorage: Handle;
- optionDialogResult: Boolean;
- canRotation: Boolean; {LS 2.6.2a}
- rotDirection: PicDirectionT; {LS 2.6.2a}
- end;
- PrmSymbolPtr = ^PrmSymbolRec;
-
-
- {Gate messages}
-
- const {LSMessageT}
- msgNewGate = 20;
- msgDisposeGate = 21;
- msgReset = 22;
- msgSimulation = 23;
- msgTimer = 24;
- msgGetGateParams = 26;
- msgStimuli = 27;
-
-
- type
- timerIDT = Longint;
-
- PrmGateRec = record
- pinUpdated: PinNumT;
- paramsStorage: Handle;
- success: Boolean;
- timerID: TimerIDT;
- stimCmd: StringPtr; {LS 2.6a}
- stimCmdHandled: Boolean; {LS 2.6a}
- end;
- PrmGatePtr = ^PrmGateRec;
-
-
- type
- LSEnvRec = record
- setOutputProc: ProcPtr;
- getInputProc: ProcPtr;
- reserved: ProcPtr;
- declarePinProc: ProcPtr;
- forceGateSimProc: ProcPtr;
- invalSymbolProc: ProcPtr;
- loopProc: ProcPtr;
- addTimerProc: ProcPtr;
- printMsgProc: ProcPtr;
- setOutputInitialValueProc: ProcPtr;
- {and other data ...}
- end;
- LSEnvPtr = ^LSEnvRec;
-
-
- ClassRefT = ^Char;
- SymbolRefT = ^Integer;
- GateRefT = ^Longint;
-
- LSParamPtr = record
- case Integer of
- 0: (
- prmClass: PrmClassPtr;
- );
- 1: (
- prmSymbol: PrmSymbolPtr;
- );
- 2: (
- prmGate: PrmGatePtr;
- );
- end;
-
- LSBlock = record
- varCode: LSVarCodeT;
- msg: LSMessageT;
- prm: LSParamPtr;
- classRef: ClassRefT;
- symbolRef: SymbolRefT;
- gateRef: GateRefT;
- classData: Handle;
- symbolData: Handle;
- gateData: Handle;
- env: LSEnvPtr;
- reserved: Longint;
- end;
-
-
- { delays }
-
- type
- MDelaysRec = record
- min: STime;
- max: STime;
- mean: STime;
- end;
- DelaysPtr = ^MDelaysRec;
-
- RFDelaysRec = record
- rise: MDelaysRec;
- fall: MDelaysRec;
- end;
-
- DelaySpec = record
- dsFamilyName: FamilyNameT;
- dsDelays: RFDelaysRec;
- end;
-
-
- procedure CallComponentDefProc (blk: LSBlock;
- proc: LSProcPtr);
- inline
- $205F, $4E90;
-
-
- procedure LSDeclarePin (env: LSEnvPtr;
- classRef: ClassRefT;
- loc: Point;
- kind: PinKindT;
- delays: DelaysPtr;
- name: PinNameT);
- procedure LSGetInput (env: LSEnvPtr;
- gateRef: GateRefT;
- pinN: PinNumT;
- var value: SValue);
- procedure LSSetOutput (env: LSEnvPtr;
- gateRef: GateRefT;
- pinN: PinNumT;
- value: SValue);
- procedure LSSetOutputInitialValue (env: LSEnvPtr;
- gateRef: GateRefT;
- pinN: PinNumT;
- value: SValue);
- procedure LSForceGateSim (env: LSEnvPtr;
- gateRef: GateRefT);
- procedure LSInvalSymbol (env: LSEnvPtr;
- symbolRef: SymbolRefT);
- procedure LSAddTimer (env: LSEnvPtr;
- gateRef: GateRefT;
- date: STime);
- procedure LSLoop (env: LSEnvPtr;
- symbolRef: SymbolRefT);
- function LSStimNewValueCmd (env: LSEnvPtr;
- cmd: StringPtr;
- var v: SValue): Boolean;
- procedure LSPrintMsg (env: LSEnvPtr;
- symOrGate: univ Ptr;
- theMessage: Str255);
-
- function GetPoint (h, v: Integer): Point;
- function CompareClassID (id1, id2: ClassIDT): Boolean;
- procedure SetClassID (var id: ClassIDT;
- s: ClassNameT);
- function LogicAND (a, b: SValue): SValue;
- function LogicOR (a, b: SValue): SValue;
- function LogicNOT (a: SValue): SValue;
- function PositiveEdge (oldV, newV: SValue): Boolean;
- function NegativeEdge (oldV, newV: SValue): Boolean;
-
- implementation
-
- function CompareClassID (id1, id2: ClassIDT): Boolean;
- begin
- CompareClassID := (id1.name = id2.name);
- end;
-
- procedure SetClassID (var id: ClassIDT;
- s: ClassNameT);
- begin
- id.name := s;
- end;
-
- function GetPoint (h, v: Integer): Point;
- var
- p: Point;
- begin
- p.h := h;
- p.v := v;
- GetPoint := p;
- end;
-
- function LogicAND (a, b: SValue): SValue;
- var
- result: SValue;
- begin
- if (a = L1) & (b = L1) then
- result := L1
- else if (a = L0) | (b = L0) then
- result := L0
- else
- result := LX;
- LogicAND := result;
- end;
-
- function LogicOR (a, b: SValue): SValue;
- var
- result: SValue;
- begin
- if (a = L1) | (b = L1) then
- result := L1
- else if (a = L0) & (b = L0) then
- result := L0
- else
- result := LX;
- LogicOR := result;
- end;
-
- function LogicNOT (a: SValue): SValue;
- var
- result: SValue;
- begin
- if a = L0 then
- result := L1
- else if a = L1 then
- result := L0
- else
- result := LX;
- LogicNOT := result;
- end;
-
- function PositiveEdge (oldV, newV: SValue): Boolean;
- begin
- PositiveEdge := ((newV = L1) & (oldV = L0));
- end;
-
- function NegativeEdge (oldV, newV: SValue): Boolean;
- begin
- NegativeEdge := ((newV = L0) & (oldV = L1));
- end;
-
- procedure Call_DeclarePin (classRef: ClassRefT;
- loc: Point;
- kind: PinKindT;
- delays: DelaysPtr;
- name: PinNameT;
- proc: ProcPtr);
- inline
- $205F, $4E90;
-
- procedure LSDeclarePin (env: LSEnvPtr;
- classRef: ClassRefT;
- loc: Point;
- kind: PinKindT;
- delays: DelaysPtr;
- name: PinNameT);
- begin
- Call_DeclarePin(classRef, loc, kind, delays, name, env^.declarePinProc);
- end;
-
- procedure Call_SetOutput (gateRef: GateRefT;
- pinN: PinNumT;
- value: SValue;
- proc: ProcPtr);
- inline
- $205F, $4E90;
-
- procedure LSSetOutput (env: LSEnvPtr;
- gateRef: GateRefT;
- pinN: PinNumT;
- value: SValue);
- begin
- Call_SetOutput(gateRef, pinN, value, env^.setOutputProc);
- end;
-
- procedure Call_SetOutputInitialValue (gateRef: GateRefT;
- pinN: PinNumT;
- value: SValue;
- proc: ProcPtr);
- inline
- $205F, $4E90;
-
- procedure LSSetOutputInitialValue (env: LSEnvPtr;
- gateRef: GateRefT;
- pinN: PinNumT;
- value: SValue);
- begin
- Call_SetOutputInitialValue(gateRef, pinN, value, env^.setOutputInitialValueProc);
- end;
-
- procedure Call_GetInput (gateRef: GateRefT;
- pinN: PinNumT;
- var value: SValue;
- proc: ProcPtr);
- inline
- $205F, $4E90;
-
- procedure LSGetInput (env: LSEnvPtr;
- gateRef: GateRefT;
- pinN: PinNumT;
- var value: SValue);
- begin
- Call_GetInput(gateRef, pinN, value, env^.getInputProc);
- end;
-
-
- procedure Call_ForceGateSim (gateRef: GateRefT;
- proc: ProcPtr);
- inline
- $205F, $4E90;
-
- procedure LSForceGateSim (env: LSEnvPtr;
- gateRef: GateRefT);
- begin
- Call_ForceGateSim(gateRef, env^.ForceGateSimProc);
- end;
-
-
- procedure Call_InvalSymbol (symbolRef: SymbolRefT;
- proc: ProcPtr);
- inline
- $205F, $4E90;
-
- procedure LSInvalSymbol (env: LSEnvPtr;
- symbolRef: SymbolRefT);
- begin
- Call_InvalSymbol(symbolRef, env^.invalSymbolProc);
- end;
-
- procedure Call_Loop (symbolRef: SymbolRefT;
- proc: ProcPtr);
- inline
- $205F, $4E90;
-
- procedure LSLoop (env: LSEnvPtr;
- symbolRef: SymbolRefT);
- begin
- Call_Loop(symbolRef, env^.loopProc);
- end;
-
-
- procedure Call_AddTimer (gateRef: GateRefT;
- date: STime;
- proc: ProcPtr);
- inline
- $205F, $4E90;
-
- procedure LSAddTimer (env: LSEnvPtr;
- gateRef: GateRefT;
- date: STime);
- begin
- Call_AddTimer(gateRef, date, env^.addTimerProc);
- end;
-
- function LSStimNewValueCmd (env: LSEnvPtr;
- cmd: StringPtr;
- var v: SValue): Boolean;
- var
- result: Boolean;
- begin
- result := true;
- if cmd^ = 'L0' then
- v := L0
- else if cmd^ = 'L1' then
- v := L1
- else if cmd^ = 'LX' then
- v := LX
- else if cmd^ = 'LZ' then
- v := LZ
- else
- result := false;
- LSStimNewValueCmd := result;
- end;
-
- procedure Call_LSPrintMsg (symOrGate: univ Ptr;
- theMessage: Str255;
- proc: ProcPtr);
- inline
- $205F, $4E90;
-
- procedure LSPrintMsg (env: LSEnvPtr;
- symOrGate: univ Ptr;
- theMessage: Str255);
- begin
- Call_LSPrintMsg(symOrGate, theMessage, env^.printMsgProc);
- end;
-
- end.